# -*- encoding:utf-8 -*-

from __future__ import unicode_literals

from django.contrib.auth.models import User
from django.db import models
from django.utils import timezone


class Category(models.Model):
    name = models.CharField(max_length=100, verbose_name=u"分类名")
    created_time = models.DateTimeField(default=timezone.now, verbose_name=u"创建时间")

    class Meta:
        verbose_name = u"分类"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.name


class Tag(models.Model):
    name = models.CharField(max_length=100, verbose_name=u"标签名")
    created_time = models.DateTimeField(default=timezone.now, verbose_name=u"创建时间")

    class Meta:
        verbose_name = "标签"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.name


class Post(models.Model):
    title = models.CharField(max_length=100, null=False, verbose_name=u"文章标题")
    excerpt = models.CharField(max_length=200, blank=True, verbose_name=u"文章摘要")
    thumbnail = models.ImageField(blank=True, null=True, upload_to='image/%Y/%m', verbose_name=u"文章缩略图")
    body = models.TextField(null=False, verbose_name=u"文章内容")
    tags = models.ManyToManyField(Tag, verbose_name=u"文章标签")
    category = models.ForeignKey(Category, verbose_name=u"分类")
    author = models.ForeignKey(User, verbose_name=u"作者")
    click_nums = models.IntegerField(default=0, verbose_name=u"浏览数")
    comment_nums = models.IntegerField(default=0, verbose_name=u"评论数")
    created_time = models.DateTimeField(default=timezone.now, null=False, verbose_name=u"创建时间")
    modified_time = models.DateTimeField(default=timezone.now, null=False, verbose_name=u"修改时间")

    class Meta:
        verbose_name = u"文章"
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.title
